package com.nxk.modules.content.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nxk.modules.content.dao.ConMessageDao;
import com.nxk.modules.content.entity.ConMessage;
import com.nxk.modules.content.service.ConMessageService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class ConMessageServiceImpl extends ServiceImpl<ConMessageDao, ConMessage> implements ConMessageService {

    @Override
    @Transactional(readOnly = false)
    public boolean save(ConMessage conMessage) {
        if (StringUtils.isNotBlank(conMessage.getId())) {
            return super.updateById(conMessage);
        } else {
            return super.save(conMessage);
        }
    }

    @Override
    public IPage<ConMessage> page(ConMessage conMessage) {
        Page<ConMessage> page = new Page<ConMessage>(conMessage.getPageNo(), conMessage.getPageSize());
        QueryWrapper<ConMessage> queryWrapper = new QueryWrapper<ConMessage>();
        if (StringUtils.isNotBlank(conMessage.getUserName())) {
            queryWrapper.lambda().like(ConMessage::getUserName, conMessage.getUserName());
        }
        queryWrapper.orderByAsc("create_date").in("status", 1, 2);
        IPage<ConMessage> result = super.page(page, queryWrapper);
        return result;

    }

    @Override
    @Transactional(readOnly = false)
    public boolean deleteById(String id) {
        return super.removeById(id);
    }

}
